<%--
  Created by IntelliJ IDEA.
  User: LXJ
  Date: 2021/6/17
  Time: 18:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>租车记录</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/component/pear/css/pear.css"/>
</head>

<%--添加分配角色的模板--%>
<script type="text/html" id="assignTpl">
    <form class="layui-form" action="" lay-filter="assign-rent">
        <div class="mainBox">
            <input name="id" type="text" hidden>
            <div class="main-container">
                <div class="main-container">
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色</label>
                        <div class="layui-input-block">
                            <ul id="roleTree" class="dtree"></ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                        lay-filter="rent-assign">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</script>

<body class="pear-container">

<%--搜索的框--%>
<div class="layui-card">
    <div class="layui-card-body ">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <form class="layui-form" action="" onsubmit="return false">
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">客户名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" required placeholder="请输入输入框内容" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">车牌号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="num" required placeholder="请输入输入框内容" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">证件号码</label>
                        <div class="layui-input-inline">
                            <input type="text" name="idCard" required placeholder="请输入输入框内容" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">是否归还</label>
                        <div class="layui-input-inline">
                            <select name="flag" lay-search>
                                <option value=""></option>
                                <option value="1">归还</option>
                                <option value="2">未归还</option>
                            </select>
                        </div>
                    </div>
                    <hr/>
                    <div class="layui-form-item layui-input-block" align="center">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="rent-query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </form>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="rent-table" lay-filter="rent-table"></table>
    </div>
</div>

<script type="text/html" id="rent-bar">
    <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="return"><i
            class="layui-icon layui-icon-return"></i>
    </button>

</script>

<script type="text/html" id="car-flag">
    <%--    rent-id 代表自定义的属性 checked=true 和false 每页效果--%>
    <input type="checkbox" name="enable" lay-skin="switch" lay-text="归还|未归还"
           {{d.flag==1 ? 'checked': ''}}></input>
</script>

<script type="text/html" id="rent-sex">
    {{#if (d.sex == 0) { }}
    <span>男</span>
    {{# }else if(d.sex == 1){ }}
    <span>女</span>
    {{# } }}
</script>

<script type="text/html" id="rent-createTime">
    {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
</script>

<script src="${pageContext.request.contextPath}/resources/component/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/resources/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'common','dtree'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let dtree = layui.dtree;


        let cols = [
            [{
                type: 'checkbox'
            },
                {
                    title: '客户名称',
                    field: 'name',
                    align: 'center',
                    width: 100
                },
                {
                    title: '车牌号',
                    field: 'num',
                    align: 'center'
                },
                {
                    title: '证件号码',
                    field: 'idCard',
                    align: 'center',
                    width: 120,
                },
                {
                    title: '租车金额',
                    field: 'rentPrice',
                    align: 'center'
                },
                {
                    title: '是否归还',
                    field: 'flag',
                    align: 'center',
                    templet: '#car-flag'
                },
                {
                    title: '租车时间',
                    field: 'beginTime',
                    align: 'center',
                },
                {
                    title: '归还时间',
                    field: 'endTime',
                    align: 'center',
                },
                {
                    title: '操作',
                    toolbar: '#rent-bar',
                    align: 'center',
                    width: 150
                }
            ]
        ]

        //Table 数据的加载
        table.render({
            elem: '#rent-table',
            url: '${pageContext.request.contextPath}/busrent/findByPage.do',
            page: true,
            // 对象的属性和table的列对应
            cols: cols,
            skin: 'line',
            toolbar: '#rent-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            // res == Result
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.data //解析数据列表
                }
            },
            response: {
                statusCode: 200
            }
        });

        table.on('tool(rent-table)', function (obj) {
            if (obj.event === 'return') {
                window.return(obj);
            }
        });

        form.on('submit(rent-query)', function (data) {
            table.reload('rent-table', {
                where: data.field
            })
            return false;
        });

        window.return = function (obj) {
            layer.confirm('确定要归还该车辆', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: "${pageContext.request.contextPath}/busreturn/return.do?rentId=" + obj.data['id'],
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code==200) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                window.refresh() ;
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }
        window.refresh = function (param) {
            table.reload('rent-table');
        }
    })
</script>
</body>
</html>

